﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Web.Script.Serialization;
using Microsoft.ApplicationBlocks.Data;
using EnglishRemix.Services.Model;
using EnglishRemix.Services.Utility;
using Newtonsoft.Json;
using System.Diagnostics;

namespace EnglishRemix.Services
{
    public class DeviceFacade
    {
        private static string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        string sqlStr = "";

        public DeviceFacade()
        {
        }

        /*************************************** get Device status *******************************************/

        public Response getDeviceStatus(string deviceId)
        {
            Response response = new Response();
            string sqlStr = "SELECT * FROM Device where Udid = '" + deviceId + "' and Enabled = 1;";
            try
            {
                DataSet ds = SqlHelper.ExecuteDataset(connStr, CommandType.Text, sqlStr);
                if (ds != null && ds.Tables.Count > 0)
                {
                    response.result = "200";
                    response.message = "Device found! This device has already been activated." + ds.Tables[0].Rows[0]["deviceId"];
                    return response;
                }
                else
                {
                    response.result = "400";
                    response.message = "Can not find device.";
                    return response;
                }
            }
            catch (Exception e)
            {
                response.result = "400";
                response.message = "Database query failed. Reason: Database query error.";
                return response;
                throw (e);
            }
        }

    }
}